﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;

using System.Text;

using Hangjing.Model;
using Hangjing.SQLServerDAL;
using Hangjing.Common;

/// <summary>
/// 骑士收入，及收支记录
/// </summary>
public partial class Android_Deliver_accountrecords : System.Web.UI.Page
{
    deliverAddMoneyLog dalorder = new deliverAddMoneyLog();
    protected void Page_Load(object sender, EventArgs e)
    {
        Response.Clear();

        StringBuilder json = new StringBuilder("");
        string SqlWhere = "  ";
        int togoid = HjNetHelper.GetPostParam("shopid", 0);
        if (togoid > 0)
        {
            SqlWhere = "UserId=" + togoid;
        }
        else {
            SqlWhere = "1=0";
        }

        string starttime = WebUtility.InputText(Request["starttime"]);//开始日期
        string endtime = WebUtility.InputText(Request["endtime"]);//结束日期


        //分页参数
        int pagesize = HjNetHelper.GetPostParam("pagesize", 10); //分页大小
        int pageindex = HjNetHelper.GetPostParam("pageindex", 1);//分页标签

        int pagecount = 1;//分页总数


        StringBuilder orderlistjson = new StringBuilder();
  

        if (starttime != "")
        {
            SqlWhere += " and AddDate >= '" + starttime + "' ";
        }
        if (endtime != "")
        {
            SqlWhere = SqlWhere + " and AddDate <=  '" + endtime + " 23:59:59'";
        }


        //Response.Write(SqlWhere);

        IncomeSumInfo count = dalorder.DeliverIncomeSum(togoid);

        orderlistjson.Append("{\"usermoney\":\"" + count.usermoney + "\",\"todaymoney\":\"" + count.todaymoney + "\",\"yetodaymoney\":\"" + count.yetodaymoney + "\",\"_7daymoney\":\"" + count._7daymoney + "\",\"_30daymoney\":\"" + count._30daymoney + "\"");

        int ordercount = dalorder.GetCount(SqlWhere);
        IList<deliverAddMoneyLogInfo> list = dalorder.GetList(pagesize, pageindex, SqlWhere, "dataid", 1);

        if (ordercount % pagesize == 0)//整数倍
        {
            pagecount = ordercount / pagesize;
        }
        else
        {
            pagecount = ordercount / pagesize + 1;
        }

        orderlistjson.Append(",\"page\":\"" + pageindex.ToString() + "\",\"total\":\"" + pagecount + "\", \"orderlist\":[");
        deliverAddMoneyLogInfo info = new deliverAddMoneyLogInfo();
        for (int i = 0; i < list.Count; i++)
        {
            info = list[i];
            orderlistjson.Append("{\"orderid\":\"" + 0 + "\",\"shopname\":\"" + info.Inve2 + "\",\"addtime\":\"" + info.AddDate.ToString("yyyy-MM-dd HH:mm:dd") + "\",\"totalmoney\":\"" + info.AddMoney + "\",\"state\":\"" + 0 + "\",\"address\":\"" + 0 + "\"");
            orderlistjson.Append(",\"PayMode\":\"" + 0 + "\"");
            orderlistjson.Append(",\"paystate\":\"" + 0 + "\"");
            orderlistjson.Append(",\"paystate\":\"" + 0+ "\"");
            orderlistjson.Append(",\"eattype\":\"" + 0 + "\"");
            orderlistjson.Append(",\"sendstate\":\"" + 0 + "\"");
            orderlistjson.Append(",\"delivergivemoney\":\"" + 0 + "\""); 
            orderlistjson.Append(",\"isfile\":\"" + 0 + "\"");

            orderlistjson.Append(",\"sendmoney\":\"" + 0 + "\"");
            orderlistjson.Append("},");
        }

        orderlistjson.Append("]}");

        Response.Write(orderlistjson.ToString().Replace("},]}", "}]}"));

        Response.End();

    }
}
